define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'recharge/index' + location.search,
                    table: 'recharge',
                }
            });

            var table = $("#table");
            
            
               //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
            });
            
            

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('用户id')},
                        {field: 'pay_coin', title: __('充值金额')},
                        {field: 'after_balace', title: __('充值后余额')},
                        {field: 'out_trade_no', title: __('订单号'),operate: 'LIKE'},
                        {field: 'transaction_id', title: __('微信订单号'),operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"unpay":'未支付',"used":'已支付',"undei":'已关闭'}, formatter: Table.api.formatter.status},
                        {field: 'addtime', title: __('变更时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
